$(document).ready(

function(){	
	$(".select-city-close").click(function(){
		$("#morecity").hide();
	});
	$(".search-frm>a").not(".more-city").click(function(){
		$(".search-frm>.cityActive").removeClass('cityActive');
		$(this).addClass("cityActive");
		return false;
	});
if($('.comments_text').length>0){
	commentInit();
}
var length=$("#bannerlist>ul>li").length;
$("#bannermenus>ul").html('');
for(var i=0;i<length;i++){
	$("#bannermenus>ul").append('<li title="'+(i==length?0:(i))+'" class="">'+(i+1)+'</li>');
}
  $("#news li").mouseover(
  function()
  {
    $("#news li dl").removeClass("select");
    $(this).find("dl").addClass("select");
  }
  );
  $("#bannermenus li").mouseover(
  function()
  {
    $("#bannermenus li").removeClass("select");
    current = $(this);
    $(this).addClass("select");
    $("#bannerlist ul").animate({top:-249*Number($(this).attr("title"))});
  }
  );
  setInterval("scrollimg()",5000);
   $("#news li").eq(0).trigger("mouseover");
});
var current = $("#bannermenus li:first");
function scrollimg()
{
  current = $(current).next();
  if($(current).length <= 0)
  current = $("#bannermenus li:first");
  $(current).mouseover();
}
function indexSearchSubmit(){	
	var city=$(".cityActive").attr("val");
	var title=$(".search-title").val();
		$(".search-keyboard").val((title||"")+","+(city||''));		
		return true;
}
function showSelectCity(){
	$(".more-city").append( $(".oDiv"));
    $(".oDiv").show();
	$("#morecity").find("a").not(".m_close").click(function(){
		$(".oDiv").hide();
		var h=$(this).html();
		$(".search-frm>.cityActive").removeClass('cityActive');
		$(".search-frm>.first").html(h).attr('val',h).show().addClass("cityActive");	
		return false;

	});
	return false;
}
function setCityValue(id){	
	$(id).parent().append( $(".oDiv"));
	
	$(this).parent().html('12345678');
    $(".oDiv").show();
	$("#morecity").find("a").not(".m_close").click(function(){
		$(".oDiv").hide();		
		var h=$(this).html();
		$(id).val(h);
		$("#morecity").find("a").not(".m_close").unbind( "click");
		return false;
		//$(".search-frm>.cityActive").removeClass('cityActive');
		//$(".search-frm>.first").html(h).attr('val',h).show().addClass("cityActive");	
		//return false;

	});
	return false;	
}
$().ready(function(){
	d_init();
})
function d_init(){
	
}
function popup_show(title,url){	
	$(".popup-box").show();
	moveToCenter(".popup-box");
	$(".popup-box").show();
	popup_loading();
	$(".popup-title").html(title);
	$(".popup-body").load(url,function(){
		$(".popup-body").show();
		$(".popup-top").show();
		setTimeout('moveToCenter(".popup-box")',0);
	});
}
function popup_loading(){
	$(".popup-body").hide();
	$(".popup-top").hide();
	$(".popup-loading").show();
	moveToCenter(".popup-box");
}
/**
***
**/
function getScreenCenter(){
	var w=(document.documentElement||document.body).clientWidth;
	var h=(document.documentElement||document.body).clientHeight;
	return [parseInt(w)/2,((parseInt(h)*48)/100)];	
}
function popUpLoadUrl(title,name,param,callback){
	$(".popup-box").show();
	moveToCenter(".popup-box");
	$(".popup-title").html(title);
	$(".popup-box").show();
	popup_loading();
	$(".popup-title").html(title);
	var sp='';
	if(param){
		for(var dex in param){
			sp+=dex+"="+param[dex]
		}
		sp="&"+sp;
	}
	if($("#newsurl").length){
		var Durl=$("#newsurl").val()+"e/module/?";
	}else{
		var Durl="../../../e/module/?";
	}
	var r=parseInt(Math.random()*10000000);
	$(".popup-body").load(Durl+name+sp+"&r="+r,function(){
		$(".popup-loading").hide();
		$(".popup-body").show();
		$(".popup-top").show();
		moveToCenter(".popup-box");
		$(window).resize(function(){moveToCenter(".popup-box");})
		$(document).scroll(function(){moveToCenter(".popup-box");})
		$(document).bind('scroll', function(){moveToCenter(".popup-box");}) 
		callback();
	});
}
function getObjWidthHeight(T){
	if((typeof T )=="string"){
		var TO=$(T);
	}else{
		var TO=T;
	}
	if(TO.css("display")=="none"){
		TO.show();
		var ishide=true;
	}	
	var w=parseInt(TO.css("width"));
	var h=parseInt(TO.css("height"));
	ishide && TO.hide();
	return [w,h];
}
function moveToCenter(T){
	var WH=getObjWidthHeight(T);

	var ScreenWH=getScreenCenter();
	if((typeof T )=="string"){
		var TO=$(T);
	}else{
		var TO=T;
	}
	var x=ScreenWH[0]-(WH[0]/2);
	var y=ScreenWH[1]-(WH[1]/2);
	//alert(ScreenWH[1]);

	//alert($(window).scrollTop());
	y=y+$(window).scrollTop();
	TO.css({left:x+"px"});
	TO.css({top:y+"px"});
	TO.trigger('scroll');
}
function showPopupMsg(msg,isShow){
	var h=$(".popup-body").height();
	var w=$(".popup-body").width();
	var jo=$(".popup-box").find(".popup-msg");
		w=w||w-1;
		h=h||h-1;
		$(".popup-body").children().hide();	
		$(".popup-loading").hide();	
		$(".popup-body").show();
	if(jo.length>0){
		$(".popup-body").children().not(".popup-msg").hide();
		$(".popup-msg").html(msg).show();
		moveToCenter(".popup-box");
	}else{		
		$(".popup-body").append("<div class='popup-msg' style='width://"+((w||"")+";")+";height://"+((h||"")+";")+"'>"+msg+"</div>");			
		$(".popup-body").children().not(".popup-msg").hide();
		//$(".popup-msg").html(msg).show();
		moveToCenter(".popup-box");
	}
	$(window).resize(function(){moveToCenter(".popup-box");})
		$(document).scroll(function(){moveToCenter(".popup-box");})
	$(".popup-box").show();
	if(window.boxmsg){clearTimeout(window.boxmsg)}
	window.boxmsg=setTimeout(function(){
		if(isShow){
			$(".popup-body").children().not(".popup-msg").show();
		}else{
			$(".popup-box").hide();
		}
		$(".popup-msg").hide();
		moveToCenter(".popup-box");
	},3000)

}
function popup_close(){
	$(".popup-box").hide();
	return false;
}
function getObject(str){
//alert('return "'+str+'"');
	var s=(new Function('return '+str+''))();
	
	return s;
}
function copyToClipboard(txt) {
 if(window.clipboardData) {
  window.clipboardData.clearData();
  window.clipboardData.setData("Text", txt);
 } else if(navigator.userAgent.indexOf("Opera") != -1) {
  window.location = txt;
 } else if (window.netscape) {
  try {
   netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
  } catch (e) {
   alert("被浏览器拒绝！\n请在浏览器地址栏输入'about:config'并回车\n然后将'signed.applets.codebase_principal_support'设置为'true'");
   //return false;
  }
  var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
  if (!clip)
   //return false;
  var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
  if (!trans)
  // return false;
  trans.addDataFlavor('text/unicode');
  var str = new Object();
  var len = new Object();
  var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
  var copytext = txt;
  str.data = copytext;
  trans.setTransferData("text/unicode",str,copytext.length*2);
  var clipid = Components.interfaces.nsIClipboard;
  if (!clip)
  // return false;
  clip.setData(trans,null,clipid.kGlobalClipboard);
 }
}
function runAtLogin(stringFunc,noDisplay){
	$.getJSON(($("#newsurl").val())+'e/jat/',{},function(d){
		if(d && d.flag==1){
			if((typeof stringFunc).toLowerCase()=="string"){
				(new Function(stringFunc))();
			}else{
				stringFunc();
			}
			window.lguserid=d.msg;
		}else if(!noDisplay){
			//showLoginForm({"callback":stringFunc});
		}
	});
}
function loadComment(p){
	var height=$(".list-c-items").height();
	$(".list-c-items").html('加载中...');
	//$(".list-c-items").css("height",height);
	var app_type=$(".comments_text>textarea").attr('app_type');
		app_type=app_type?app_type:'';
	var url=($("#newsurl").val())+"e/comment/list.php?p="+(p?p:1)+"&type="+app_type+"&app_id="+($("#comment_app_id").val())+"&tmp="+parseInt(Math.random()*10000);
	$(".list-c-items").load(url,function(){
		//$(".list-c-items").css("height","auto");
		var cmNum=$("#cmmt_t_num").val();
		$(".comment_num").html(cmNum);
	})
}
function commentInit(){
	$(".submitbtn").click(function(){//提交内容
	if(window.uploading==true){
		alert('请勿重复提交！');
		return false;
	}
		var app_type=$(".comments_text>textarea").attr('app_type');
		app_type=app_type?app_type:'';
		var content=$(".comments_text>textarea").val();
		if(!content){alert("内容不能为空！");return false;}
		if(content.length<2){alert("内容不能小于两个字!");return false;}
		if(content.length>200){
			if(!confirm('字符超过限制，系统将自动截取200个字，是否继续？')){
				return false;
			}
			content=content.subString(0,200);
		}
		$(".comments_text>textarea").attr("disabled",'disabled');
		window.uploading=true;
		$.ajax({type:"POST",dataType:"json",data:{"dataFromType":"ajax","type":app_type,"act":"add_comment","content":content,"app_id":($("#comment_app_id").val())},url:($("#newsurl").val())+"e/comment/",success:function(r){
			if(r.flag==1){
				$(".comments_text>textarea").val("").attr("disabled",'');
				window.uploading=false;
				loadComment();					
				return false;
			}else if(r.msg){alert(r.msg);}else{alert("系统错误，请与管理员联系");}
				
	}});	
	});
	loadComment();
}